//
//  AddYunDanOneCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/9/17.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "AddYunDanOneCell.h"

@interface AddYunDanOneCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UITextField *contentField;
@property (nonatomic, strong) UIButton *cangKuBtn;
@property (nonatomic, strong) UILabel *countTitleLab;
@property (nonatomic, strong) UILabel *countLab;
@property (nonatomic, strong) UIButton *sureBtn;

@end

@implementation AddYunDanOneCell

+ (instancetype)AddYunDanOneCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"AddYunDanOneCell";
    AddYunDanOneCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[AddYunDanOneCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(15, 10, ScreenW - 30, 142)];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.nameLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, self.bgView.nim_width - 40, 19)];
        self.nameLab.font = BoldFontOfSize(18);
        self.nameLab.textColor = HexColor(0x2B2C44);
        [self.bgView addSubview:self.nameLab];
        
        self.sureBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.bgView.nim_width - 20 - 64, self.bgView.nim_height - 15 - 30, 64, 30)];
        self.sureBtn.backgroundColor = Color_ThemeColor;
        self.sureBtn.layer.masksToBounds = YES;
        self.sureBtn.layer.cornerRadius = 15;
        [self.sureBtn setTitle:@"确认" forState:0];
        [self.sureBtn setTitleColor:HexColor(0xffffff) forState:0];
        self.sureBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.sureBtn addTarget:self action:@selector(sureClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.sureBtn];
        
        self.contentField = [[UITextField alloc] initWithFrame:CGRectMake(20, (self.sureBtn.nim_top - self.nameLab.nim_bottom - 32) * 0.5 + self.nameLab.nim_bottom, self.bgView.nim_width - 40, 32)];
        self.contentField.backgroundColor = HexColor(0xF7F7FA);
        self.contentField.layer.masksToBounds = YES;
        self.contentField.layer.cornerRadius = 4;
        self.contentField.layer.borderWidth = 1;
        self.contentField.layer.borderColor = HexColor(0xF2F2F5).CGColor;
        self.contentField.textColor = HexColor(0x2B2C44);
        self.contentField.font = [UIFont systemFontOfSize:14];
        self.contentField.placeholder = @"请选择仓库";
        [self.bgView addSubview:self.contentField];
        
        UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 12, self.contentField.nim_height)];
        leftView.backgroundColor = HexColor(0xF7F7FA);
        self.contentField.leftView = leftView;
        self.contentField.leftViewMode = UITextFieldViewModeAlways;
        
        UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 42, self.contentField.nim_height)];
        rightView.backgroundColor = HexColor(0xF7F7FA);
        UIImageView *arrowImgView = [[UIImageView alloc] initWithFrame:CGRectMake(12, 7, 18, 18)];
        arrowImgView.image = [UIImage imageNamed:@"icon_add_yundan_arrow"];
        [rightView addSubview:arrowImgView];
        self.contentField.rightView = rightView;
        self.contentField.rightViewMode = UITextFieldViewModeAlways;
        
        self.cangKuBtn = [[UIButton alloc] initWithFrame:self.contentField.frame];
        [self.cangKuBtn addTarget:self action:@selector(cangKuClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.cangKuBtn];
        
        self.countTitleLab = [UILabel new];
        self.countTitleLab.textColor = HexColor(0x9C9DB3);
        self.countTitleLab.font = [UIFont systemFontOfSize:14];
        self.countTitleLab.text = @"提货单数：";
        [self.countTitleLab sizeToFit];
        self.countTitleLab.nim_left = 20;
        self.countTitleLab.nim_centerY = self.sureBtn.nim_centerY;
        [self.bgView addSubview:self.countTitleLab];
        
        self.countLab = [UILabel new];
        self.countLab.font = BoldFontOfSize(20);
        self.countLab.textColor = HexColor(0x2B2C44);
        self.countLab.text = @"0";
        [self.countLab sizeToFit];
        self.countLab.nim_left = self.countTitleLab.nim_right;
        self.countLab.nim_centerY = self.countTitleLab.nim_centerY;
        self.countLab.nim_width = self.sureBtn.nim_left - self.countLab.nim_left;
        [self.bgView addSubview:self.countLab];
        
        self.height = self.bgView.nim_bottom;
    }
    return self;
}

- (void)cangKuClick {
    if (self.selectBlock) {
        self.selectBlock();
    }
}

- (void)sureClick {
    if (self.sureBlock) {
        self.sureBlock();
    }
}

-(void)setModel:(AddYunDanWuLiuCompanyModel *)model {
    _model = model;
    self.nameLab.text = model.name;
    if (model.selectCangKu.w_id.length) {
        self.countLab.text = model.selectCangKu.dp_num;
        self.contentField.text = model.selectCangKu.name;
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
